<#include '/admin/header.html' >
<#assign dateformat= "com.enation.framework.directive.DateformateDirective"?new()>
<#assign permssion= "com.enation.app.base.core.directive.PermssionDirective"?new()>
<script type="text/javascript">
	//如果不是已审核 那么跳转到入库页面 
	if(${sellBackList.tradestatus}>0){
		location.href = "${ctx}/shop/admin/sell-back/returned.do?id=${sellBackList.id}";
	}
</script>


<style>
.info{
	background-color: white;
	margin-top: 10px;
	padding: 10px;
	margin-bottom: 60px;
}
.layui-elem-field legend{
	margin-left: 0px;
	padding:  0px 30px;
	margin: 0px;
}

.sellback-info .table-info td:nth-child(1),.sellback-info .table-info td:nth-child(3){
	background-color: #eeeeee;
	width: 150px;
	text-align: center;
}

.sellback-info .layui-form-item{
	display:inline;
}

</style>

<div class="admin-main">
	<form class="layui-form layui-form-pane" id="theForm" >
	<input type="hidden" value="${sellBackList.id}" name="id"/>
		<div class="info sellback-info">
			<fieldset>
				<legend>退货单详情</legend>
			</fieldset>
			
			<table class="layui-table table-info" >
				<thead>
					<tr>
						<th class="title" colspan="4" style="color: #FF5722;" >申请退货信息</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>关联订单号：</td>
						<td><a href='javascript:void(0);' onclick="newTab('订单信息','${ctx}/shop/admin/order/detail.do?orderId=${orderinfo.order_id}')">${orderinfo.sn }</a></td>
						<td>退货单号：</td>
						<td>${sellBackList.tradeno }</td>
					</tr>
					<tr>
						<td>已支付金额</td>
						<td>￥${orderinfo.paymoney}</td>
						<td>商品金额</td>
						<td>￥${orderinfo.goods_amount}</td>
						<input type="hidden"  id="paypricereturn" value="${orderinfo.paymoney!''}"/>
					</tr>
					<tr>
						<td>运费</td>
						<td>￥${orderinfo.shipping_amount}</td>
						<td>申请退款金额</td>
						<td>${sellBackList.apply_alltotal!'0'}</td>
					</tr>
					<tr>
						<td>退货人</td>
						<td>${orderinfo.ship_name }</td>
						
					</tr>
					<tr>
						<td>退货原因</td>
						<td>${sellBackList.reason!''}</td>
						<td>退货描述</td>
						<td>${sellBackList.remark!''}</td>
					</tr>
				</tbody>
			</table>
			
			<table  class="layui-table"  cellspacing="0" cellpadding="0" border="0" id="orderbasedata">
				<thead>
					<tr>
						<th class="title" colspan="5" style="color: #FF5722;" >退货单商品</th>
					</tr>
					<tr>
						<th>商品名称</th>
						<th>商品货号</th>
						<th>金额</th>
						<th>购买数量</th>
						<th>退货数量</th>
					</tr>
				</thead>
				
				<#list goodsList as data>
					<tr>
						<td>
							<a target="_blank" href="${ctx}/goods-${data.goods_id}.html">${data.goods_name }${data.spec!''}</a> 
						</td>
						<td>${data.goods_sn!0 }</td>
						<td>${data.price?string.currency}</td>
						<td>${data.ship_num!0 }</td>
						<td>${data.return_num!0}</td>
					</tr>
				</#list>
				<!-- 退货赠品信息 add_by DMRain 2016-7-19 -->
				<#if (gift.gift_id)??>
					<tr>
						<td><span style="color: #4287cf;">${gift.gift_name!''}</span><span style="color: red;">(赠品)</span></td>
						<td></td>
						<td>${gift.gift_price?string.currency}</td>
						<td>1</td>
						<td>1</td>
					</tr>
				</#if>
			</table>
			<br>
			<hr>
			
			<div class="layui-form-item w400">
				<label class="layui-form-label">退款金额</label>
				<div class="layui-input-block">
				<input type="hidden" value="${payCfg.is_retrace}" class="refund_way">
					<input type="text" name="alltotal_pay" lay-verify="required|money" class="layui-input" value="${sellBackList.apply_alltotal!'0'}" >
				</div>
			</div>
			
			<div class="layui-form-item w400">
				<label class="layui-form-label">退款仓库</label>
				<div class="layui-input-block">
					<select id="depotid" name="depotid" class="input_text" lay-verify="required" >
						<option value="0">请选择退货仓库</option>
						<#list depotlist as dl >
							<#if depotid?? && depotid == dl.id >
								<option value="${dl.id }" selected="selected" >${dl.name }</option>
							<#else>
								<option value="${dl.id }" >${dl.name }</option>
							</#if>
						</#list>
					</select>
				</div>
			</div>
			
			<div class="layui-form-item w400">
				<label class="layui-form-label">退款审核</label>
				<div class="layui-input-block">
					<input type="radio" name="status" value="1" checked="checked" title="通过" />
					<input type="radio" name="status" value="2" title="不通过" />
				</div>
			</div>
			
			<div class="layui-form-item w400">
				<label class="layui-form-label">操作备注</label>
				<div class="layui-input-block">
					<textarea name="seller_remark"  placeholder="请输入" class="layui-textarea"></textarea>
				</div>
			</div>

			
			<div class="save-div">
				<a class="layui-btn layui-btn-normal" lay-submit lay-filter="sellbackBtn">立即保存</a>
			</div>

		</div>	
	</form>	
</div>


<script>


//获取支付方式
var pay_way=$(".refund_way").val();

//注意：选项卡 依赖 element 模块，否则无法进行功能性操作
layui.use(['element','upload','form'], function() {
	var element = layui.element();
	var upload = layui.upload();
	var form = layui.form();

	form.verify({  
		 money: function(value){  
			 if(pay_way == 1){
				 if(Number(value) == 0){  
		        	  return "退款金额不能为0";
		          } 
				}
	          if(Number(value) < 0){  
	        	  return "退款金额不能为负数";
	          } 
	          if(Number(value) > Number($("#paypricereturn").val())){  
	        	  return "退款金额不能大于已支付金额";
	          }
	          if (isNaN(value)) {
	        	  return "退款金额格式有误！";
			}
	        }
	 });
	//监听提交
	form.on('submit(sellbackBtn)', function(data){
		
		var options = {
			url : "${ctx}/shop/admin/sell-back/save-auth.do",
			type : "POST",
			dataType : 'json',
			success : function(result){
				
				if(result.result==1){
					$.Loading.success(result.message);
					location.href="${ctx}/shop/admin/order-report/returned-list.do";
				}
				if(result.result==0){ 
					$.Loading.error(result.message);
				}
			},
			error : function(e) {
				$ ("#saveBtn").linkbutton("enable");  
				$.Loading.error("出现错误 ，请重试");
			}
		};
		$("#theForm").ajaxSubmit(options); 
		return false;
	});
	
});

</script>

<#include '/admin/footer.html' >